#include<stdio.h>

void swap(int* x, int* y)
{
	int tem = *x;
	*x = *y;
	*y = tem;
}

void SelectSort(int* arr,int n)
{
	int begin = 0;
	int end = n - 1;
	while (begin < end)
	{
		int maxi = end;
		int mini = begin;
		for (int i = begin; i <= end; i++)
		{
			if (arr[i] > arr[maxi])
			{
				maxi = i;
			}
			if (arr[i] < arr[mini])
			{
				mini = i;
			}
		}
		if (maxi == begin)
		{
			maxi = mini;
		}
		swap(&arr[mini], &arr[begin]);
		swap(&arr[maxi], &arr[end]);
		begin++;
		end--;
	}
}


